<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/19-15:47
 * Link: https://gitee.com/luckygyl/LuckyAdmin
 * FileName: index.html
 *-->

{include file="public/head" /}

<body>
<!-- 正文开始 -->
<div class="layui-fluid">

    <div class="layui-row layui-col-space10">

        <div class="layui-col-md12">

            <div class="layui-card">
                <div class="layui-card-body layui-row ">
                    <form action="" class="layui-form" method="get" >
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">文章搜索：</label>
                                <div class="layui-input-inline">
                                    <input name="title" class="layui-input" value="" type="text" placeholder="请输入标题">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">文章栏目·：</label>
                                <div class="layui-input-inline">
                                    <select name="navigate_id" lay-search="">
                                        <option value="">请选择栏目</option>
                                        {volist name="navigate" id="v"}
                                        <option value="{$v.id}">├─ {$v.title}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline" style="padding-left: 20px;">
                                <button class="layui-btn icon-btn" lay-filter="search" lay-submit="">
                                    <i class="layui-icon"></i>搜索
                                </button>
                                <button class="layui-btn icon-btn layui-btn-normal"  onclick="javascript:window.location.reload();" >
                                    <i class="layui-icon layui-icon-refresh"></i> 重置
                                </button>
                            </div>

                        </div>

                    </form >
                </div>

            </div>

            <!--右侧表格开始-->
            <div class="layui-card">
                <div class="layui-card-header" style="line-height: 55px;">
                    <div class="layui-btn-container do_btn">
                        <button class="layui-btn layui-btn-sm layui-btn-danger"  data-type="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                        <button class="layui-btn layui-btn-sm" data-type="add"> <i class="layui-icon">&#xe61f;</i>新增文章</button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary"  data-type="reload"> <i class="fa fa-refresh"></i> 刷新</button>
                        <button class="layui-btn layui-btn-sm layui-btn-warm"   data-type="move"> <i class="layui-icon layui-icon-spread-left"></i>移动文章</button>
                        <button class="layui-btn layui-btn-normal layui-btn-sm"  onmouseover="tis(this)" lay-submit="" lay-filter="export" data-title="导出表格全部数据">
                            <i class="fa fa-tags"></i> 导出数据
                        </button>
                    </div>
                </div>
                <div class="layui-card-body">


                  <div class="yys-fluid yys-wrapper">
                        <div class="layui-row lay-col-space20">
                            <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                                <section class="yys-body">
                                    <div class="yys-body-content clearfix changepwd">
                                        <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                            <div class="user-tables">
                                                <table id="tableFilter" lay-filter="tableFilter"> </table>
                                            </div>
                                        </div>
                                    </div>
                                </section>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <!--右侧表格结束-->

        </div>


    </div>




</div>

<style type="text/css">
    .layui-table-cell{
        text-align:center;
        height: auto;
        white-space: normal;
    }
    .layui-table img{
        max-width:300px;
        max-height: 50px;
    }
</style>

<!--模板-->
<script type="text/html" id="operationTpl">
    <a href="javascript:;"   class="layui-btn layui-btn-normal layui-btn-xs "  onmouseover="tis(this)"  data-title="编辑文章" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a href="javascript:;"   class="layui-btn layui-btn-warm layui-btn-xs "  onmouseover="tis(this)"  data-title="下架文章" lay-event="down"><i class="layui-icon layui-icon-download-circle"></i></a>
    <a href="javascript:;"   class="layui-btn layui-btn-danger layui-btn-xs "  onmouseover="tis(this)"  data-title="删除文章" lay-event="del"><i class="layui-icon " >&#xe640;</i></a>
</script>


<script type="text/html" id="is_top">
    <input type="checkbox" name="is_top"  lay-data="{{d.is_top}}" value="{{d.id}}"  lay-filter="sexDemo" lay-skin="switch"  lay-text="是|否"  {{ d.is_top == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="recomend">
    <input type="checkbox" name="is_recommend"  lay-data="{{d.is_recommend}}" value="{{d.id}}"  lay-filter="sexDemo" lay-skin="switch"  lay-text="是|否"  {{ d.is_recommend == 1 ? 'checked' : '' }}>
</script>

{include file="public/js" /}


<script>
    layui.config({
        base: "{__FRAME_PATH}/js/soultable/",   // 模块目录
        version: 'v1.0'
    }).extend({                         // 模块别名
        soulTable: 'soulTable'
    });
    layui.use(['element', 'table', 'form', 'jquery', 'laydate','util','soulTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var util=layui.util;
        var  soulTable = layui.soulTable;

        form.render();

        //layer.load(2);
        var myTable=table.render({
            elem: '#tableFilter',
            url:"{:url('article/index')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:15
                ,limits:[15,30,40,60,80,100]
            },
            height: $(document).height() - $('#tableFilter').offset().top - 20
             ,
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                // {field: 'id',  title: 'ID',width:60},
                {field: 'image_url', title: '文章缩略图', style:'cursor: pointer;',width: 150, align: "center",templet:function (d) {
                        return '<div><img src="'+d.image_url+'"  layer-index="100" alt="无图" /></div>';
                    }},
                {field: 'title', minWidth: 200, title: '文章标题',templet:function (d) {
                        return '<a target="_blank" href="'+d.url+'"  title="点击查看原文信息" >'+d.title+'</a>';
                    }},
                {field: 'navigate_title',style:'cursor: pointer;',title: '所属栏目',filter: true,width: 120},
                //{field: 'description',style:'cursor: pointer;',title: '文章摘要',width: 200},
                {field: 'source',style:'cursor: pointer;',title: '文章类型',filter: true,width: 120},
                {field: 'is_recommend',style:'cursor: pointer;',title: '推荐',filter: true,width: 100,templet:"#recomend"},
                {field: 'author',style:'cursor: pointer;',title: '作者',width: 100},
                {field: 'status',style:'cursor: pointer;',title: '状态',filter: true,width: 85,templet:function (d) {
                    var s="";
                        if (d.status==1){
                            s='<font color="green">正常</font>';
                        } else if(d.status==2){
                            s='<font color="color">下架</font>';
                        }else {
                            s='<font color="orange">草稿</font>';
                        }
                        return s;
                    }},
                {field: 'hits',style:'cursor: pointer;',title: '点击量',width: 100,sort:true},
                {field: 'is_top',style:'cursor: pointer;',title: '置顶',width: 100,templet:"#is_top"},
                {field: 'comment_nums',style:'cursor: pointer;',title: '评论数',width: 100,sort:true},
                {field: 'time_formt', title: '发布时间',align: 'center',width:160},
                { width:138, align:'center',templet: '#operationTpl',title: '操作'}
            ]],
            filter: {
                items:['column','data','condition','editCondition','excel'] //用于控制表头下拉显示，可以控制顺序、显示
                ,bottom: true // 是否显示底部筛选区域，默认为true
            },

            done: function (res) {
                soulTable.render(this);
                //layer.closeAll('loading');
                hoverOpenImg();
            }
        });


        /**
         * 鼠标悬浮显示大图
         *
         */
        function hoverOpenImg(){
            var img_show = null; // tips提示
            $('td img').hover(function(){
                var img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:100%;max-height: 600px;' />";
                img_show = layer.tips(img, this,{
                    tips:[2, 'rgba(41,41,41,.0)']
                    ,area: ['12%']
                });
            },function(){
                layer.close(img_show);
            });
        }

        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            CreateSearch("table_id",obj.field); //查询
            return false;
        });


        //导出数据
        form.on('submit(export)', function () {
            soulTable.export(myTable);
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;

            if(layEvent==="del"){
                delete_data(_id,"{:url('article/delete')}","table_id");

            }else if(layEvent==="edit"){
                var urls="/index.php/admin/article/EditArticle/id/"+_id;
                CreateForm("编辑文章",'10%','10%',urls,"table_id",0,1);
            }else if(layEvent==="down"){
                layer.confirm("确定下架该文章？", function(index){
                    layer.close(index);
                    $.ajax({
                        beforeSend:function(){
                            layer.load(2);
                        },
                        url: "{:url('article/down')}",
                        type: "POST",
                        async: true,
                        dataType: "json",
                        data:{
                            id: _id,
                        },
                        error: function(error) {
                            layer.msg("服务器错误或超时");
                            return false;
                        },
                        success: function(data) {
                            if (data.code==1) {
                                layer.msg(data.msg,{icon:1,time:1500,shade:0.3,anim:4});
                                setTimeout(function(){
                                    CreateReload("table_id");
                                    //重载表格数据
                                },500);
                            }else{
                                layer.msg(data.msg,{icon:15,time:1500,shade:0.3},function () {
                                    CreateReload("table_id");
                                });
                            }
                        },
                        complete:function(){
                            layer.closeAll('loading');
                        }
                    });
                });
            }
            else {
                layer.msg("功能待开发",{time:1500});return false;
            }

        });


        var active = {
            add:function(){
                CreateForm("新增文章",'10%','10%',"{:url('article/AddArticle')}","table_id",0,1);
            },
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                delete_data(id,"{:url('article/delete')}","table_id");
            },
            reload: function(){
                CreateReload("table_id");
            },
            move:function () {
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                 var ids = id.join(',');

                layer.open({
                    title:"批量移动文章",
                    type: 1,
                    offset:'auto;',
                    area: ["250px", "50%"],
                    btn: ["确定","取消"],
                    skin:'layui-layer-molv',
                    shade: 0.5,
                    content: $('#model')//
                    ,yes: function(index){
                        $.ajax({
                            url:"{:url('article/move_article')}",
                            type:'post',
                            data:{ids:ids,navigate_id:parseInt($("#navigate_id").val())},
                            error: function(error) {
                                layer.msg("服务器错误或超时");
                                return false;
                            },
                            beforeSend:function(){
                                layer.load(2);
                            },
                            success:function(data)
                            {
                                if (data.code==1) {
                                        layer.msg(data.msg,{icon: 1, time: 1500,shade:0.3, anim: 4},function () {
                                            layer.close(index);
                                        });
                                }else{
                                    layer.msg(data.msg,{icon:15,time:1500,shade:0.3,anim:4});
                                }
                            },
                            complete:function(){
                                layer.closeAll('loading');
                            }
                        });
                    }
                    ,btn2: function(index, layero){
                      layer.close(index);
                    },
                    success:function () {
                        form.render("select");
                    },
                    end:function () {
                        CreateReload("table_id");
                    }
                });
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >

</body >

<div class="layui-fluid" style="display: none;" id="model">
    <div class="layui-row layui-form" >
        <select lay-search="" id="navigate_id">
            {volist name="navigate" id="v"}
            <option value="{$v.id}">├─ {$v.title}</option>
            {/volist}
        </select>
    </div>
</div>

</html >